﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Day06
{
    //事件源
    public class MainCity
    {
        public float Hp { get; set; }
        public float MaxHp { get; set; }
        public string Name { get; set; }
        public Action OnDamage;//委托

        //public event Action<DamageEventArgs> OnDamageEventHandler;//事件：相对于多播委托区别，只对外提供+=、-=功能
        public event DamageEventHandler OnDamageEventHandler;//自写的委托，同上
        public void Damage()
        {
            //Alarm.Open();
            //Enclosure.Upgrade();
            //受伤逻辑
            Hp -= 10;

            if (OnDamage != null)
            {
                OnDamage();
            }
           

            //具有响应者
            if (OnDamageEventHandler != null)
            {
                //构建事件参数类对象
                DamageEventArgs args = new DamageEventArgs()
                {
                    Sender = this,
                    LifeRatio = Hp / MaxHp
                };
                //引发事件
                OnDamageEventHandler(args);
            }
        }
        public void PrintHp()
        {
            Console.WriteLine(Hp);
        }
        private void Fun1()
        {
            Console.WriteLine("私有方法");
        }
    }
}